
package com.scs.application.modules.cert.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.cert.entity.Certificate;
import com.scs.application.modules.cert.mapper.CertificateMapper;
import com.scs.application.modules.cert.request.CertificateQueryRequest;
import com.scs.application.modules.cert.service.CertificateService;
import com.scs.application.modules.design.service.QueryGenerator;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 预定义资质 controller
 */
@AllArgsConstructor
@RestController
@RequestMapping("/cert/certificates")
public class CertificateController extends CrudController<Certificate, String, CertificateService> implements ImAndExAbleController<CertificateQueryRequest> {
    private final CertificateMapper certificateMapper;
    @GetMapping("/page")
    public PageResult page(CertificateQueryRequest request) {
        IPage page = service.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    /**
     * 查询当前医院下不存在的资质信息
     *
     * @param request
     * @return
     */
    @GetMapping("/page_hospital_not_existed")
    public PageResult pageHospitalNotExisted(CertificateQueryRequest request) {
        IPage<Certificate> page = service.pageHospitalNotExisted(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());

    }

    @GetMapping("/list")
    public CommonResult list(CertificateQueryRequest request) {
        List<Certificate> list = service.list(request);
        return CommonResult.ok("查询成功", list);
    }

    // 院方资质定义列表左侧使用
    @GetMapping("/listForHpdefineSelect")
    public CommonResult listForHpdefineSelect(CertificateQueryRequest request) {
        return CommonResult.ok("查询成功", certificateMapper.listForHpdefineSelect());
    }

    // 院方资质定义添加使用
    @GetMapping("/pageForHpdefineAdd")
    public PageResult pageForHpdefineAdd(HttpServletRequest request, Certificate entity) {
        IPage<Certificate> page = QueryGenerator.parsePage(request);
        QueryWrapper<Certificate> queryWrapper = QueryGenerator.initQueryWrapper(request);
        fillQueryAuth(queryWrapper,entity);
        IPage pageResult = certificateMapper.pageForHpdefineAdd(page, queryWrapper, UserUtils.getHospitalId());
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }


}
